package com.zang.array;

/**
 * @Author: ZVerify
 * @Description: https://leetcode.cn/problems/backspace-string-compare/
 * @DateTime: 2022/10/2 12:46
 **/
public class 比较含退格的字符串 {
    // 这道题表面是个easy，其实如果考虑复杂度的话不是easy了就，很多细节需要考虑
    // 模拟栈
    public boolean backspaceCompare(String s, String t) {

       String l =  func(s);
       String r =  func(t);

        return l.equals(r);
    }

    private String func(String s) {

        int i = 0;
        StringBuilder builder = new StringBuilder();
        while (i<s.length()){
            if (s.charAt(i)=='#'){
                if (builder.length()>0){
                    builder.deleteCharAt(builder.length()-1);
                }

            }else{
                builder.append(s.charAt(i));
            }
            i++;
        }
        return builder.toString();
    }
}
